/*
  SOLID - Interference Detection Library
  Copyright (C) 1997 Gino van den Bergen

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

  Please send remarks, questions and bug reports to gino@win.tue.nl,
  or write to:
                  Gino van den Bergen
		  Department of Mathematics and Computing Science
		  Eindhoven University of Technology
		  P.O. Box 513, 5600 MB Eindhoven, The Netherlands
*/

#ifndef _BBOXTREE_H_
#define _BBOXTREE_H_

#include "Transform.h"
#include "BBox.h"
#include "Polygon.h"
#include "PointBuf.h"

class BBoxTree {
private:
  enum Tag { INTERNAL, LEAF };

  struct Internal {
    BBoxTree *left;
    BBoxTree *right;
  };
  
  struct Leaf {
    const Polygon **polys;
    int npolys;
  };
  
  BBox bound;
  Tag tag;
  union {
    Internal internal;
    Leaf leaf;
  };

  // Never used!!
  BBoxTree(const BBoxTree& x);
  const BBoxTree& operator=(const BBoxTree& x);
  
public:
  BBoxTree() {}
  BBoxTree(int n, const Polygon **p);
  ~BBoxTree();
  
  const BBox& volume() const { return bound; }
  bool isLeaf() const { return tag == LEAF; } 
  
  friend bool intersect(const BBoxTree& tree1, const BBoxTree& tree2, 
			const Transform& t, const Matrix& m);
  friend void intersect(const BBoxTree& tree1, const BBoxTree& tree2, 
			const Transform& t, const Matrix& m, PointBuf& report);
};

#endif






